home *** CD-ROM | disk | FTP | other *** search
- Path: newshost.lanl.gov!tanmoy
- From: tanmoy@qcd.lanl.gov (Tanmoy Bhattacharya)
- Newsgroups: comp.lang.c
- Subject: Re: Examples of using "volatile"?
- Date: 19 Jan 1996 16:33:57 GMT
- Organization: Los Alamos National Laboratory
- Message-ID: <TANMOY.96Jan19093357@qcd.lanl.gov>
- References: <4djoj2$mr1@post.gsfc.nasa.gov> <4dm91p$bsi@info.uah.edu>
- <4dnf7f$1sa@fountain.mindlink.net>
- NNTP-Posting-Host: qcd.lanl.gov
- Mime-Version: 1.0
- Content-Type: text
- In-reply-to: genew@mindlink.bc.ca's message of Fri, 19 Jan 1996 06:53:15 GMT
-
- --text follows this line--
- In article <4dnf7f$1sa@fountain.mindlink.net> genew@mindlink.bc.ca
- (Gene Wirchenko) writes:
- <snip>
- >Basically, like most modifiers, volatile is a hint to the compiler
- >that the value of i could change at any time, and not to take its
- >value for granted. Of course, the compiler could ignore you since
- >it's only a hint, but that wouldn't be a very good compiler :)
-
- No, it wouldn't because it would be broken. K&R2, used as a sub
- for the Standard by those of us without $120 or so to spend on said
- Standard, says on page 211 (in the indented portion at the bottom):
- "The purpose of volatile is to force an implementation to
- suppress optimization that could otherwise occur."
- Note the word "force".
-
- Actually, the standard does almost make it a hint (note the
- almost). The standard is absolutely clear that a volatile access
- (i.e. accessing a volatile variable) cannot be optimized away: but the
- meaning of `access' is left free to the implementer :-) They couldn't
- have done much else without going to the definition of hardware, I
- think.
-
- The intent of the standard is however clear. And I would refuse to buy
- a compiler which optimized my use of volatile away ... on the pretext
- that a nop constitues an `access'.
-
- Cheers
- Tanmoy
- --
- tanmoy@qcd.lanl.gov(128.165.23.46) DECNET: BETA::"tanmoy@lanl.gov"(1.218=1242)
- Tanmoy Bhattacharya O:T-8(MS B285)LANL,NM87545 H:#9,3000,Trinity Drive,NM87544
- Others see <gopher://yaleinfo.yale.edu:7700/00/Internet-People/internet-mail>,
- <http://alpha.acast.nova.edu/cgi-bin/inmgq.pl>or<ftp://csd4.csd.uwm.edu/pub/
- internetwork-mail-guide>. -- <http://nqcd.lanl.gov/people/tanmoy/tanmoy.html>
- fax: 1 (505) 665 3003 voice: 1 (505) 665 4733 [ Home: 1 (505) 662 5596 ]
-